<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * 模块:会员订单模块
 * 开发:胡耆英
 * 创建日期: 2011-6-09
 * 
 */
class Order extends B_Controller
{
	public function __construct()
	{
		parent::__construct();
		parent::check_login();
	}
	
	public function index()
	{
		echo 'orders';
	}
	
	/*
	*通过ajax查看会员订单信息
	*/
	public function order_detail()
	{
		$oid = $this->input->post('oid');
		$data['orders'] = M('orderbag')->where(array('oid'=>$oid))->findall();
		if(!empty($data['orders']))
		{
			$this->load->view('order_input',$data);
		}
		else
		{
			echo 'noorders';
		}
	}
	/*
	*通过ajax查看快递情况
	*/
/*	public function check_ship_detail()
	{
		$api = KUAIDI100_API;
		$shipnumber = $this->input->post('shipnumber');
		$shiptype = $this->input->post('shiptype');
		$url = "http://api.kuaidi100.com/api?id={$api}&com={$shiptype}&nu={$shipnumber}&show=0&muti=1&order=asc";
		$result = get_data_from_url($url);
		if(!empty($result))
		{
			$arr = object_array(json_decode($result));
			if($arr['status']==1)
			{
				$data['ship'] = $arr['data'];
				$this->load->view('ship_detail',$data);
			}
			elseif($arr['status']==2)
			{
				echo 'inexistence'; //单号不存在
			}
			else
			{
				echo 'failed';
			}
		}
		else
		{
			echo 'failed';//获取数据失败
		}
	}*/
	//上面的代码是通过ajax实现的,但是版面的不美观,实在是无奈改成了跳转的方式
	public function check_ship_detail()
	{
		$api = KUAIDI100_API;
		$shipnumber = $this->uri->segment(3);
		$shiptype = $this->uri->segment(4);
		$url = "http://api.kuaidi100.com/api?id={$api}&com={$shiptype}&nu={$shipnumber}&show=0&muti=1&order=asc";
		$result = get_data_from_url($url);
		if(!empty($result))
		{
			$arr = object_array(json_decode($result));
			if($arr['status']==1)
			{
				$data['ship'] = $arr['data'];
				$data['title'] =$shipnumber.'单号查询';
				$data['keyword'] ="查询结果";
				$data['shipnumber'] = $shipnumber;
				$this->load->view('ship_detail',$data);
			}
			elseif($arr['status']==2)
			{
				show_message('单号不存在',site_url('order/index'),1);
			}
			else
			{
				show_message('查询数据失败',site_url('order/index'),1);
			}
		}
		else
		{
			echo 'failed';//获取数据失败
		}
	}
}
?>